package com.liming.auth.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liming.auth.mapper.RoleMenuMapper;
import com.liming.auth.service.RoleMenuService;
import com.liming.common.pojo.entity.authinfo.RoleMenu;
import com.liming.common.util.mybatisplus.MPUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author liming
 * @date 2025/2/16
 */
@Service
@AllArgsConstructor
public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenu>
        implements RoleMenuService, MPUtil<RoleMenu> {

    @Override
    public List<Long> menuIdsByRoleId(Long id) {
        return lambdaQuery().eq(RoleMenu::getRoleId, id).list().stream().map(RoleMenu::getMenuId).toList();
    }

    @Override
    public Boolean removeByRoleId(Long id) {
        return lambdaUpdate().eq(RoleMenu::getRoleId, id).remove();
    }

    @Override
    public List<Long> menuIdsByRoleIds(List<Long> roleIds) {
        return lambdaQuery().in(RoleMenu::getRoleId, roleIds).list().stream().map(RoleMenu::getMenuId).distinct().toList();
    }

    @Override
    public Boolean removeByMenuId(Long id) {
        return lambdaUpdate().eq(RoleMenu::getMenuId, id).remove();
    }
}
